package com.huike.web.controller.clues;

import com.huike.clues.domain.TbCourse;
import com.huike.clues.service.TbCourseService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 课程管理Controller
 *
 * @date 2023-04-01
 */
@RestController
@Api(tags = "课程管理相关接口")
@RequestMapping("/clues/course")
@Slf4j
public class TbCourseController extends BaseController {

    @Resource
    private TbCourseService tbCourseService;

    /*查询课程管理列表*/
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('clues:course:list')")
    @ApiOperation("查询课程管理列表")
    public TableDataInfo list(TbCourse tbCourse) {
        startPage();
        List<TbCourse> tbCourseList = tbCourseService.selectTbCourseList(tbCourse);
        return getDataTable(tbCourseList);
    }

    /*
    * 新增
    * */
    @PostMapping
    @ApiOperation("新增课程")
    public AjaxResult addCourse(@RequestBody TbCourse tbCourse){
        tbCourseService.addCourse(tbCourse);
        return AjaxResult.success();
    }

    /*
    * 返现数据
    * */
    @ApiOperation("获取课程管理详细信息")
    @GetMapping("/{id}")
    public AjaxResult getCourseById(@PathVariable Integer id){
        TbCourse tbCourse = tbCourseService.getCourseById(id);
        return AjaxResult.success(tbCourse);
    }


    @ApiOperation("课程下拉列表")
    @GetMapping("/listselect")
    public AjaxResult getListselect(String subject){
        TbCourse query = new TbCourse();
        if(subject!=null){
            query.setSubject(subject);
        }
        List<TbCourse> tbCourseList = tbCourseService.getListselect(query);
        return AjaxResult.success(tbCourseList);
    }

    /*
    * 修改
    * */
    @PutMapping
    @ApiOperation("修改课程管理")
    public AjaxResult updateCourse(@RequestBody TbCourse tbCourse){
        tbCourseService.updateCourse(tbCourse);
        return AjaxResult.success();
    }

    /*
    * 批量删除课程管理
    * */
    @ApiOperation("批量删除课程管理")
    @DeleteMapping("/{ids}")
    public AjaxResult deleteCourseByIds(@PathVariable List<Integer> ids){
        tbCourseService.deleteCourseByIds(ids);
        return AjaxResult.success();
    }
}
